import { http } from '../utils/request.js'

// ========================================
// 🔧 系统监控 API
// ========================================

// 健康检查
export const healthCheck = () => {
  return http.get('/health')
}

// 获取系统信息
export const getSystemInfo = () => {
  return http.get('/system/info')
}

// 获取系统统计报告
export const getSystemStats = () => {
  return http.get('/system/stats')
}

// 获取用户活动日志
export const getUserActivityLogs = (params = {}) => {
  const { page = 1, pageSize = 20, userId, startDate, endDate } = params
  let url = `/system/logs/user-activity?page=${page}&pageSize=${pageSize}`
  
  if (userId) url += `&userId=${userId}`
  if (startDate) url += `&startDate=${startDate}`
  if (endDate) url += `&endDate=${endDate}`
  
  return http.get(url)
}

// 获取系统错误日志
export const getSystemErrorLogs = (params = {}) => {
  const { page = 1, pageSize = 20, level, startDate, endDate } = params
  let url = `/system/logs/errors?page=${page}&pageSize=${pageSize}`
  
  if (level) url += `&level=${level}`
  if (startDate) url += `&startDate=${startDate}`
  if (endDate) url += `&endDate=${endDate}`
  
  return http.get(url)
}

// 获取性能监控数据
export const getPerformanceMetrics = (params = {}) => {
  const { type = 'all', timeRange = '24h' } = params
  return http.get(`/system/performance?type=${type}&timeRange=${timeRange}`)
}

// 获取在线用户统计
export const getOnlineUsersStats = () => {
  return http.get('/system/online-users')
}

// 获取活跃房间统计
export const getActiveRoomsStats = () => {
  return http.get('/system/active-rooms')
}

// 统一导出系统监控API
export const statsAPI = {
  healthCheck,
  getSystemInfo,
  getSystemStats,
  getUserActivityLogs,
  getSystemErrorLogs,
  getPerformanceMetrics,
  getOnlineUsersStats,
  getActiveRoomsStats
} 